<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>盒子居中-flex布局</title>
  <style>
    /* flex布局让盒子居中
    1. 父级设置display:flex
    2. 子级设置margin:auto
    */
    .father {
      width: 500px;
      height: 500px;
      background-color: pink;
      display: flex;
    }

    .son {
      width: 20%;
      height: 20%;
      background-color: purple;
      margin: auto;
    }
  </style>
</head>
<body>
  <div class="father">
    <div class="son"></div>
  </div>
</body>
</html>